﻿<Page
    x:Class="BingMapsSearch_WinRT_CS.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BingMapsSearch_WinRT_CS"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:m="using:Bing.Maps">

    <Page.Resources>
        <Style TargetType="Button">
            <Setter Property="Background" Value="Green"/>
        </Style>
    </Page.Resources>
    
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <!-- Left Side Panel -->
        <ScrollViewer Background="Gray">
            <StackPanel Margin="10,10,20,10">
                <!-- Clear Map Button -->
                <Button Content="Clear Map" Click="ClearMapBtn_Click" 
                        HorizontalAlignment="Right"/>

                <!-- Geocode Input -->
                <TextBlock Text="Geocode" FontSize="24"/>
                <Grid>
                    <TextBox Name="GeocodeTbx" HorizontalAlignment="Left" 
                             Width="220" Height="25"/>
                    <Button Content="Geocode" HorizontalAlignment="Right" 
                            Click="GeocodeBtn_Click"/>
                </Grid>

                <!-- Route Input -->
                <TextBlock Text="Route" FontSize="24" Margin="0,10,0,0"/>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="From:" FontSize="18"/>
                    <TextBox Name="FromTbx" Width="220" Margin="10,0,0,0"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="To:" FontSize="18"/>
                    <TextBox Name="ToTbx" Width="220" Margin="33,10,0,10"/>
                </StackPanel>
                <Button Content="Get Directions" Click="RouteBtn_Click" 
                        HorizontalAlignment="Right"/>

                <!-- Geocode Results Panel -->
                <ListBox Name="GeocodeResults" 
                         SelectionChanged="GeocodeResultSelected" Margin="0,10,0,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

                <!-- Route Itinerary Panel -->
                <StackPanel Name="RouteResults">
                    <ListBox ItemsSource="{Binding RouteLegs}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <ListBox ItemsSource="{Binding ItineraryItems}">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <TextBlock Text="{Binding Instruction.Text}" 
                                                           TextWrapping="Wrap" Width="200"/>
                                                <TextBlock Text="{Binding TravelDistance}" 
                                                           Margin="10,0,0,0" />
                                                <TextBlock Text="km"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>

        <!-- Map Area -->
        <m:Map Name="MyMap" Grid.Column="1" Credentials="YOUR_BING_MAPS_KEY"/>
    </Grid>
</Page>
